//
//  GenderEditViewController.Action.swift
//  App_Profile
//
//  Created by 蒋晨成 on 2022/2/11.
//

import Center
import Foundation
import UICore
import UIKit

extension GenderEditViewController {
    func bind() {}

    @objc
    func cancel() {
        UIView.animate(withDuration: 0.25) {
            self.genderPickerView.snp.updateConstraints {
                $0.bottom.equalToSuperview().offset(self.genderPickerView.frame.height + 44)
            }
            self.view.backgroundColor = .clear
            self.view.layoutIfNeeded()
        } completion: { [self] _ in
            self.dismiss(animated: false, completion: nil)
        }
    }

    @objc
    func confirm() {
        if currentGenderIndex == UserCenter.userInfo?.gender {
            cancel()
            return
        }
        view.makeToastActivity(.center)
        UserCenter.updateBasicProfile(gender: currentGenderIndex) { [weak self] result in
            self?.view.hideToastActivity()
            switch result {
            case .success:
                self?.cancel()
            case .failure(let error):
                self?.view.makeToast(error.localizedDescription, position: .center)
            }
        }
    }
}
